<?php
class news
{
	var $row;
	var $obj;
	var $city;
	var $db;
	var $objId;
	var $id;
	function __construct($obj, $city, $objId)
	{
		$this->db=substr($obj, 0, 1).'n';
		$this->city=$city;
		$this->objId=$objId;
		$this->obj=$obj;
	}
	function addStyle()
	{		echo ('
		<link rel="stylesheet" type="text/css" href="style/news.css" />
		');
	}
	function showANews($id, $name, $text, $date, $link, $textSubstr="")
	{		$foto='';
		$imgSrc='';
		$text=nl2br($text);
		$date=date_create($date);
		$date=date_format($date, 'd-m-Y');
		$url='http://pro-gorod.com/pictures/'.$this->obj.'newspics/'.$this->city.'/'.$id.'.jpg';
		if(@fopen($url, "r"))
			$imgSrc='http://pro-gorod.com/pictures/'.$this->obj.'newspics/'.$this->city.'/'.$id.'.jpg';
		if($imgSrc)
			$foto='<img class="newsPic" src="'.$imgSrc.'" />';
		echo ('
		<div class="new">
			<table border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td colspan="2">
						<div class="newsdate" align="center">
							'.$date.'
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<div class="newsName">
							'.$name.'
						</div>
					</td>
				</tr>
				<tr>
					<td class="newsinfo" align="center" colspan="2">
						<div class="newsfoto">
                        	'.$foto.'
						</div>
					</td>
				</tr>
				<td>
					<td class="newsbody">
						<div class="newstext">
							'.$text.'
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center" class="newspers">
					</td>
				</tr>
			</table>
		</div>
		');
	}
	function showNews($link, $limit="", $lim="", $textSubstr="")
	{
		if($limit)$LIMIT="LIMIT ".$limit;
		if($lim)$LIMIT="LIMIT ".$lim.', '.$limit;
		$aConnect=new connect($this->db);
		$newsNum=mysql_num_rows($aConnect->select_all($this->city, "WHERE ".$this->obj."_id='".$this->objId."'"));
		$res=$aConnect->select_all($this->city, "WHERE ".$this->obj."_id='".$this->objId."' ORDER BY data DESC $LIMIT");
		echo ('
		<div class="news">
			');
		while($row=mysql_fetch_array($res))
		{
			$this->showANews($row['id'], $row['name'], $row['stext'], $row['data'], $link, $textSubstr);
		}
		echo ('
		</div>
		'.$showAllLink.'
		');
	}
}
?>